import 'package:card_swiper/card_swiper.dart';
import 'package:flutter/material.dart';

class BannerSwiper extends StatelessWidget {
  final List<String> imageUrls;
  final Function(int)? onTap;

  const BannerSwiper({
    Key? key,
    required this.imageUrls,
    this.onTap,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AspectRatio(
      aspectRatio: 16 / 9, // 保持宽高比
      child: Swiper(
        itemCount: imageUrls.length,
        itemBuilder: (context, index) {
          return GestureDetector(
            onTap: () => onTap?.call(index),
            child: Image.network(imageUrls[index], fit: BoxFit.cover),
          );
        },
        autoplay: true,
        pagination: SwiperPagination(),
        control: SwiperControl(),
      ),
    );
  }
}
